﻿using System;
using System.Collections.Generic;
using System.Text;

namespace VkSample42
{
    /// <summary>
    /// 六角星
    /// </summary>
    public class SixPointedStar
    {
        /// <summary>
        /// 数据
        /// </summary>
        public float[] Data { get; set; }
        /// <summary>
        /// 顶点数
        /// </summary>
        public uint VCount { get; set; }
        /// <summary>
        /// 创建数据
        /// </summary>
        /// <param name="R"></param>
        /// <param name="r"></param>
        /// <param name="z"></param>
        public void CreateStarData(float R, float r, float z)
        {
            List<float> alVertix = new List<float>();
            float tempAngle = 360 / 6;
            float unitSize = 1;
            for(float angle = 0; angle < 360; angle += tempAngle)
            {
                alVertix.AddRange(new float[] { 0, 0, z });
                alVertix.AddRange(new float[] { R * unitSize * MathF.Cos(ToRadians(angle)), R * unitSize * MathF.Sin(ToRadians(angle)), z });
                alVertix.AddRange(new float[] { r * unitSize * MathF.Cos(ToRadians(angle + tempAngle / 2)), r * unitSize * MathF.Sin(ToRadians(angle + tempAngle / 2)), z });
                alVertix.AddRange(new float[] { 0, 0, z });
                alVertix.AddRange(new float[] { r * unitSize * MathF.Cos(ToRadians(angle + tempAngle / 2)), r * unitSize * MathF.Sin(ToRadians(angle + tempAngle / 2)), z });
                alVertix.AddRange(new float[] { R * unitSize * MathF.Cos(ToRadians(angle + tempAngle)), R * unitSize * MathF.Sin(ToRadians(angle + tempAngle)), z });
            }
            VCount = (uint)(alVertix.Count / 3);
            Data = new float[alVertix.Count * 2];
            int index = 0;
            for(int i = 0; i < VCount; i++)
            {
                Data[index++] = alVertix[i * 3 + 0];
                Data[index++] = alVertix[i * 3 + 1];
                Data[index++] = alVertix[i * 3 + 2];
                if (i % 3 == 0)
                {
                    Data[index++] = 1;
                    Data[index++] = 1;
                    Data[index++] = 1;
                }
                else
                {
                    Data[index++] = 0.45f;
                    Data[index++] = 0.75f;
                    Data[index++] = 0.75f;
                }
            }
        }

        private float ToRadians(float angle)
        {
            return angle / 180.0f * MathF.PI;
        }
    }
}
